﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercice4
    {
    enum choix : int { AJOUTER = 1, MULTIPLIER = 2, SOUSTRAIRE = 3, QUITTER = 4 }
    class Program
        {
        delegate int ProcessDelegate(int v, int a);
        static int add(int v, int a)
            {
            return v + a;
            }
        static int sub(int v, int a)
            {
            return v - a;
            }
        static int mul(int v, int a)
            {
            return v * a;
            }

        static void Main(string[] args)
            {
            ProcessDelegate process;
            int v = 0;
            while (true)
                {
                System.Console.WriteLine("| v = {0} |", v);
                switch (menu())
                    {
                    case (int)choix.AJOUTER:
                    process = add;
                    v = process(v, 1);
                    break;

                    case (int)choix.MULTIPLIER:
                    process = mul;
                    v = process(v, 2);
                    break;

                    case (int)choix.SOUSTRAIRE:
                    process = sub;
                    v = process(v, 4);
                    break;

                    case (int)choix.QUITTER:
                    System.Environment.Exit(0);
                    break;

                    default:
                    break;
                    }

                
                }
            }

        static int menu()
            {
            System.Console.WriteLine("1. Ajouter 1");
            System.Console.WriteLine("2. Multiplier par 2");
            System.Console.WriteLine("3. Soustraire 4");
            System.Console.WriteLine("4. Quitter");

            String str = System.Console.ReadLine();
            Int32 i = 0;
            try
                {
                i = Convert.ToInt32(str);
                }
            catch (Exception)
                {
                i = 4;
                System.Console.WriteLine("Erreur d'entrée !");
                }

            return i;
            }
        }
    }
